#!/bin/bash


EXPECTED_ARGS=1

if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: `basename $0` <delay in seconds between starting server and starting client>"
  exit $E_BADARGS
fi


for i in {0..3}
	do
		CMD="java -jar ../mp3.jar services$i.ini topology.ini "
		echo $CMD 
		FIFO=/tmp/myfifo.$i
		rm -f $FIFO
		mkfifo $FIFO
		eval "($CMD) > $FIFO & "
		pids[$i]=$!
		cat $FIFO | tee $i.log &
	done

sleep $1s

CMD="java -jar ../imdbclient.jar topology.ini lookuplatency"
echo $CMD
sleep 1s
eval "($CMD) | tee client.log "


for i in "${pids[@]}"
	do
		kill $i
	done
